// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import fastclick from 'fastclick'
import 'lib-flexible'
// router transition animation
import vueg from 'vueg'
import 'vueg/css/transition-min.css'
import axios from 'axios'
import {BASE_IMG_URL} from '@/api/common'

const options = {
  duration: '0.3',              // 转场动画时长，默认为0.3，单位秒
  firstEntryDisable: false,     // 值为true时禁用首次进入应用时的渐现动画，默认为false
  firstEntryDuration: '.6',     // 首次进入应用时的渐现动画时长，默认为.6
  forwardAnim: 'fadeInRight',   // 前进动画，默认为fadeInRight
  backAnim: 'fadeInLeft',       // 后退动画，默认为fedeInLeft
  sameDepthDisable: false,      // url深度相同时禁用动画，默认为false
  tabs: [],                     // 默认为[]，'name'对应路由的name,以实现类似app中点击tab页面水平转场效果，如tabs[1]到tabs[0]，会使用backAnim动画，tabs[1]到tabs[2]，会使用forwardAnim动画
  tabsDisable: false,           // 值为true时，tabs间的转场没有动画，默认为false
  shadow: true,                 // 值为false，转场时没有阴影的层次效果
  disable: false                // 禁用转场动画，默认为false，嵌套路由默认为true
}
Vue.use(vueg, router, options, BASE_IMG_URL)

// vueTouch vue手势插件
const VueTouch = require('vue-touch')
Vue.use(VueTouch, {name: 'v-touch'})

// fastclick 用以接管原生click事件，解决touchend和click混用导致的点击穿透
fastclick.attach(document.body)

//  定义全局变量
Vue.prototype.BASE_IMG_URL = BASE_IMG_URL
Vue.prototype.aimUrl = ''

Vue.config.productionTip = false

// document.body.ontouchmove = function (e) {
//   e.preventDefault()
// }
// var overscroll = function (el) {
//   el.addEventListener('touchstart', function () {
//     var top = el.scrollTop
//     var totalScroll = el.scrollHeight
//     var currentScroll = top + el.offsetHeight
//     // If we're at the top or the bottom of the containers
//     // scroll, push up or down one pixel.
//     // this prevents the scroll from "passing through" to
//     // the body.
//     if (top === 0) {
//       el.scrollTop = 1
//     } else if (currentScroll === totalScroll) {
//       el.scrollTop = top - 1
//     }
//   })
//   el.addEventListener('touchmove', function (evt) {
//     // if the content is actually scrollable, i.e. the content is long enough
//     // that scrolling can occur
//     if (el.offsetHeight < el.scrollHeight) {
//       evt._isScroller = true
//     }
//   })
// }
// overscroll(document.body)
// document.body.addEventListener('touchmove', function (evt) {
//   // In this case, the default behavior is scrolling the body, which
//   // would result in an overflow.  Since we don't want that, we preventDefault.
//   if (!evt._isScroller) {
//     evt.preventDefault()
//   }
// })

// Vue.prototype.$http = axios
axios.interceptors.request.use(function (config) {
  store.dispatch('showloading')
  return config
}, function (err) {
  return Promise.reject(err)
})
axios.interceptors.response.use(function (response) {
  store.dispatch('hideloading')
  return response
}, function (err) {
  return Promise.reject(err)
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
